package edu.cuit.jead.mynetdisk.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.cuit.jead.mynetdisk.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mybatis.spring.annotation.MapperScan;

import java.math.BigInteger;
import java.sql.Date;

@Mapper
@MapperScan
public interface UserMapper extends BaseMapper<User> {
    @Select("SELECT MAX(id) FROM user")
    BigInteger getMaxId();
    @Select("SELECT CURRENT_TIME()")
    Date getCurrentTime();
    @Select("SELECT * FROM user WHERE email=#{email}")
    User getUserByEmail(String email);
    @Select("SELECT * FROM user WHERE username=#{username}")
    User getUserByName(String name);
    @Update("UPDATE user SET token=#{token} WHERE email=#{email}")
    int updateToken(@Param("token") String token,@Param("email") String email);
    @Update("UPDATE user SET avatar = #{avatar} WHERE email = #{email}")
    int updateAvatar(@Param("avatar") String avatar,@Param("email") String email);
    @Update("UPDATE user SET username=#{username} WHERE email=#{email}")
    int updateUsername(@Param("username") String username,@Param("email") String email);
    @Update("UPDATE user SET password=#{password} WHERE email=#{email}")
    int updatePassword(@Param("password") String password,@Param("email") String email);
}
